//导入 axios 
import axios from 'axios';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { toast } from 'react-toastify';
//创建对象
let instance = axios.create({
    baseURL : 'http://127.0.0.1:3001'
});

//声明拦截器
instance.interceptors.request.use(config => {
    NProgress.start();
    //请求拦截器必须要返回配置对象
    return config;
});

//添加响应拦截器
instance.interceptors.response.use(response => {
    NProgress.done();
    //请求拦截器必须要返回配置对象
    return response.data;
}, error => {
    //请求失败后, 提示
    toast.error('请求异常, 请稍后再试!!');
    //中断 promise 链条
    return new Promise(() => {});
});

//暴露
export default instance;